<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑角色</title>
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.5.5/css/layui.css}"
          href="../../../static/layuimini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" href="../../../static/layuimini/css/public.css"
          media="all">
    <style>
        body {
            background-color: #fff;
            padding: 0;
            margin: 0;
        }

        body .layui-layer-btn {
            background-color: #F8F8F8;
            border-top: 1px solid #eee;
            padding-top: 10px;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <form id="roleInfoForm">
        <div class="layui-form-item"></div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色名：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="roleName" th:value="${sysRole!=null?sysRole.roleName:''}"
                       lay-verify="required" placeholder="请输入名称" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid" style="color: red">*</div>
        </div>

        <!--隐藏域-->
        <input id="roleId" type="hidden" name="roleId" th:value="${param.roleId}">
        <div class="layui-layer-btn layui-layer-btn-">
            <a id="per_save" class="layui-layer-btn0" lay-filter="btn_save" lay-submit>保存</a>
            <a id="edit_cancel" class="layui-layer-btn1">关闭</a>
        </div>
    </form>
</div>

<script th:src="@{/layuimini/lib/layui-v2.5.5/layui.js}" src="../../../static/layuimini/lib/layui-v2.5.5/layui.js"
        charset="utf-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" src="../../../static/layuimini/js/lay-config.js?v=1.0.4"
        charset="utf-8"></script>
<script th:inline="text">
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;


        form.on('submit(btn_save)',function (){
            save();
            return false;
        })
        //保存
        function save() {
            var roleInfoFormData = $('#roleInfoForm').serialize();
            console.log(roleInfoFormData);
            layer.load(2);
            $.ajax({
                type: 'post',
                url: '[[@{/}]]manage/role/roleSave',
                data: roleInfoFormData,
                dataType: 'json',
                success: function (result) {
                    console.log(result);
                    if (result.success){
                        layer.msg("保存成功");
                        $('#roleId').val(result.data.roleId);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    layer.msg(textStatus);
                },
                complete: function () {
                    layer.closeAll('loading');
                }
            });
        }

        //取消
        $('#edit_cancel').click(function cancel() {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

        form.render();
    });
</script>
</body>
</html>